<!DOCTYPE html>
<html>
<head>
    <title>导出功能调试</title>
</head>
<body>
    <h1>分镜导出功能调试</h1>
    <button onclick="testPDFExport()">测试PDF导出</button>
    <button onclick="testExcelExport()">测试Excel导出</button>
    <button onclick="testTextExport()">测试文本导出</button>
    
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/exceljs/4.3.0/exceljs.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.5/FileSaver.min.js"></script>
    
    <script>
        function testPDFExport() {
            try {
                console.log('开始测试PDF导出...');
                const { jsPDF } = window.jspdf;
                const doc = new jsPDF();
                
                doc.text('测试分镜脚本', 20, 20);
                doc.text('场景1: 测试场景', 20, 30);
                
                const pdfBlob = doc.output('blob');
                saveAs(pdfBlob, 'test-storyboard.pdf');
                console.log('PDF导出成功');
            } catch (error) {
                console.error('PDF导出失败:', error);
                alert('PDF导出失败: ' + error.message);
            }
        }
        
        function testExcelExport() {
            try {
                console.log('开始测试Excel导出...');
                const workbook = new ExcelJS.Workbook();
                const worksheet = workbook.addWorksheet('分镜场景清单');
                
                worksheet.addRow(['场景编号', '场景标题', '时长']);
                worksheet.addRow([1, '测试场景', 10]);
                
                workbook.xlsx.writeBuffer().then(buffer => {
                    const blob = new Blob([buffer], {
                        type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
                    });
                    saveAs(blob, 'test-storyboard.xlsx');
                    console.log('Excel导出成功');
                });
            } catch (error) {
                console.error('Excel导出失败:', error);
                alert('Excel导出失败: ' + error.message);
            }
        }
        
        function testTextExport() {
            try {
                console.log('开始测试文本导出...');
                const content = '测试分镜脚本\n场景1: 测试场景\n时长: 10秒';
                const blob = new Blob([content], { type: 'text/plain;charset=utf-8' });
                saveAs(blob, 'test-storyboard.txt');
                console.log('文本导出成功');
            } catch (error) {
                console.error('文本导出失败:', error);
                alert('文本导出失败: ' + error.message);
            }
        }
    </script>
</body>
</html>